from app import db


class Station(db.Model):
    __tablename__ = 'station_info'
    station_id = db.Column(db.Integer, primary_key=True, autoincrement=False)
    station_name = db.Column(db.TEXT)
    image = db.Column(db.TEXT)
    area = db.Column(db.TEXT)
    capacity = db.Column(db.TEXT)
    location = db.Column(db.TEXT)
    time_build = db.Column(db.TEXT)
    brief = db.Column(db.TEXT)
    feature = db.Column(db.TEXT)


class Monthly_result(db.Model):
    __tablename__ = 'show_data'
    station_id = db.Column(db.Integer, primary_key=True, autoincrement=False)
    weather_data = db.Column(db.TEXT)
    solar_data = db.Column(db.TEXT)
    power_data = db.Column(db.TEXT)
    generation_data = db.Column(db.TEXT)


# 解析数据库反馈的类
class JsonHelper():
    def jsonBQlist(bqlist):
        result = []
        for item in bqlist:
            jsondata = {}
            for i in range(item.__len__()):
                tdic = {item._fields[i]: item[i]}
                jsondata.update(tdic)
            result.append(jsondata)
        return result

    def string_list(string):
        return [float(i) for i in (string.split(','))]

